Telegram Group & Telegram Channel
Slugify :

Converts a string to a URL-friendly slug.



Use str.lower() and str.strip() to normalize the input string.

Use re.sub() to to replace spaces, dashes and underscores with - and remove special characters
.

Code:


import re
def slugify(s):
s = s.lower().strip()
s = re.sub(r'[^\w\s-]', '', s)
s = re.sub(r'[\s_-]+', '-', s)
s = re.sub(r'^-+|-+$', '', s)
return s

EXAMPLE

slugify('Hello World!')

Output:
'hello-world'

Share and Support
@Python_Codes



tg-me.com/python_codes/142
Create:
Last Update:

Slugify :

Converts a string to a URL-friendly slug.



Use str.lower() and str.strip() to normalize the input string.

Use re.sub() to to replace spaces, dashes and underscores with - and remove special characters
.

Code:


import re
def slugify(s):
s = s.lower().strip()
s = re.sub(r'[^\w\s-]', '', s)
s = re.sub(r'[\s_-]+', '-', s)
s = re.sub(r'^-+|-+$', '', s)
return s

EXAMPLE

slugify('Hello World!')

Output:
'hello-world'

Share and Support
@Python_Codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/142

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

However, analysts are positive on the stock now. “We have seen a huge downside movement in the stock due to the central electricity regulatory commission’s (CERC) order that seems to be negative from 2014-15 onwards but we cannot take a linear negative view on the stock and further downside movement on the stock is unlikely. Currently stock is underpriced. Investors can bet on it for a longer horizon," said Vivek Gupta, director research at CapitalVia Global Research.

Python Codes from us


Telegram Python Codes
FROM USA